﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;

using PaintDotNet.Web.Data;


public partial class getImage : System.Web.UI.Page
{
    string user;
    string imageId;
    imageType type;

    public getImage()
    { 
        
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        user = Request.Params["userId"];
        if (Session.SessionID == Request.Params["userId"])
        {
            imageId = Request.Params["id"];
            int intType = Convert.ToInt32(Request.Params["type"]);
            type = util.convertIntToImageType(intType);

            Bitmap imagen = new Bitmap(util.getUserImage(user, imageId, type, true));
            //Cuidado GIFs, mirar Paint.NET
            Graphics grphcs = Graphics.FromImage(imagen);

            grphcs.DrawString(user,
                new Font("Arial", 20, FontStyle.Bold), Brushes.Black, new PointF(0, 0));
            Response.ContentType = "image";
            imagen.Save(Response.OutputStream, ImageFormat.Jpeg);
        }
        else
        {
            Response.ContentType = "image/jpg";
            byte[] _bytes = new byte[1];
            _bytes[0] = 0;
            Response.OutputStream.Write(_bytes, 0, 0);

        }
    }
}
